package com.lwf.config.spider;

import com.lwf.component.spider.article.ArticlePipelineline;
import com.lwf.component.spider.iteye.boke.IteyeBokeProcessor;
import com.lwf.component.spider.iteye.essence.IteyeEssenceProcessor;
import com.lwf.component.spider.iteye.information.IteyeInformationProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import us.codecraft.webmagic.Spider;

@Configuration
public class SpiderConfig {
    @Autowired
    private IteyeEssenceProcessor iteyeEssenceProcessor;
    @Autowired
    private ArticlePipelineline articlePipelineline;
    @Autowired
    private IteyeBokeProcessor iteyeBokeProcessor;
    @Autowired
    private IteyeInformationProcessor iteyeInformationProcessor;

    @Bean("iteyeEssenceSpider")
    public Spider initIteyeEssenceSpider() {
        Spider spider = Spider.create(iteyeEssenceProcessor)
                .addUrl("http://www.iteye.com/magazines?page=1")
                .addPipeline(articlePipelineline)
                //开启5个线程抓取
                .thread(1);
        return spider;
    }

    @Bean("iteyeBokeSpider")
    public Spider initIteyeBokeSpider() {
        Spider spider = Spider.create(iteyeBokeProcessor)
                .addUrl("http://www.iteye.com/blogs?page=1")
                .addPipeline(articlePipelineline)
                //开启5个线程抓取
                .thread(1);
        return spider;
    }
    @Bean("iteyeInformationSpider")
    public Spider initIteyeInformationSpider(){
        Spider spider = Spider.create(iteyeInformationProcessor)
                .addUrl("http://www.iteye.com/news?page=1")
                .addPipeline(articlePipelineline)
                //开启5个线程抓取
                .thread(1);
        return spider;
    }

}
